﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

namespace XiamenQudianCoffee.model
{
    public class CoffeeMakes
    {
        private static CoffeeMakes instance;
        private CoffeeMakes() { }

        public static CoffeeMakes Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CoffeeMakes();
                }
                return instance;
            }
        }
        /// <summary>
        /// 预存单
        /// </summary>
        public List<CoffeeMakeModel> coffeeMakes { get; set; } = new List<CoffeeMakeModel>();
        /// <summary>
        /// 正在制作
        /// </summary>
        public List<CoffeeMakeModel> coffeeMaking { get; set; } = new List<CoffeeMakeModel>();
        /// <summary>
        /// 不能预制
        /// </summary>
        public List<CoffeeMakeModel> coffeeMaked { get; set; } = new List<CoffeeMakeModel>();
        /// <summary>
        /// 压盖流程
        /// </summary>
        /// <param name="LGInit">第几个压盖</param>
        public void YGMsg(int LGInit)
        {
            try
            {
                while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                IOMsg.Instance.CFBol = false;
                IOMsg.Instance.AllBol = false;
                if (LGInit == 1)
                {
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionUP1_Sel_Bol) { Thread.Sleep(100); }
                    while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                    IOMsg.Instance.CFBol = false;
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (WuLiaoCoffeeSel.Instance.LidOff1_Sel_Bol) { Thread.Sleep(10); }
                    while (!WuLiaoCoffeeSel.Instance.LidOff1_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG1_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown1_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionFront1_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    int lidZ = 0;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionMiddle1_Sel_Bol)
                    {
                        Thread.Sleep(100);
                        lidZ++;
                        if (lidZ == 30)
                            break;
                    }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_end);
                    Thread.Sleep(1000);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown1_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionBehind1_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_end);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                }
                else if (LGInit == 2)
                {
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionUP2_Sel_Bol) { Thread.Sleep(100); }
                    while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                    IOMsg.Instance.CFBol = false;
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (WuLiaoCoffeeSel.Instance.LidOff2_Sel_Bol) { Thread.Sleep(10); }
                    while (!WuLiaoCoffeeSel.Instance.LidOff2_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG2_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown2_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionFront2_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    int lidZ = 0;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionMiddle2_Sel_Bol)
                    {
                        Thread.Sleep(100);
                        lidZ++;
                        if (lidZ == 30)
                            break;
                    }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_end);
                    Thread.Sleep(1000);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown2_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionBehind2_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_end);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                }
                else if (LGInit == 3)
                {
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionUP3_Sel_Bol) { Thread.Sleep(100); }
                    while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                    IOMsg.Instance.CFBol = false;
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (WuLiaoCoffeeSel.Instance.LidOff3_Sel_Bol) { Thread.Sleep(10); }
                    while (!WuLiaoCoffeeSel.Instance.LidOff3_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG3_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown3_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionFront3_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    int lidZ = 0;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionMiddle3_Sel_Bol)
                    {
                        Thread.Sleep(100);
                        lidZ++;
                        if (lidZ == 30)
                            break;
                    }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_end);
                    Thread.Sleep(1000);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionDown3_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_start);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    while (!WuLiaoCoffeeSel.Instance.LidOffPositionBehind3_Sel_Bol) { Thread.Sleep(10); }
                    IOMsg.Instance.AllBol = false;
                    Thread.Sleep(200);
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_end);
                    Thread.Sleep(200);
                    IOMsg.Instance.AllBol = true;
                    IOMsg.Instance.CFBol = true;
                }
                IOMsg.Instance.AllBol = true;
                IOMsg.Instance.CFBol = true;
                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_YGWC_UP);
                Thread.Sleep(200);
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// 门升
        /// </summary>
        public void OutMealClose(int ccInit)
        {
            try
            {
                while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                IOMsg.Instance.CFBol = false;
                bool bol = false;
                Console.WriteLine("yes2");
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_start);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_start);
                Console.WriteLine("yes3");
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                Thread.Sleep(200);
                if (ccInit == 1)
                {
                    while (true)
                    {
                        Console.WriteLine("yes4");
                        if (!WuLiaoCoffeeSel.Instance.BANNER1_Sel_Bol)
                        {
                            IOMsg.Instance.AllBol = true;
                            if (WuLiaoCoffeeSel.Instance.PushRodUP1_Sel_Bol)
                            {
                                Console.WriteLine("yes7");
                                IOMsg.Instance.AllBol = false;
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                                Thread.Sleep(200);
                                IOMsg.Instance.AllBol = true;
                                bol = false;
                                break;
                            }
                            Thread.Sleep(200);
                        }
                        else
                        {
                            Console.WriteLine(DateTime.Now.ToString());
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                            while (true)
                            {
                                if (WuLiaoCoffeeSel.Instance.PushRodUP1_Sel_Bol)
                                {
                                    Console.WriteLine("yes9");
                                    IOMsg.Instance.AllBol = false;
                                    Thread.Sleep(200);
                                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                                    Thread.Sleep(200);
                                    IOMsg.Instance.AllBol = true;
                                    bol = false;
                                    break;
                                }
                                if (!WuLiaoCoffeeSel.Instance.BANNER1_Sel_Bol)
                                {
                                    bol = true;
                                    break;
                                }
                                Thread.Sleep(200);
                                Console.WriteLine(DateTime.Now.ToString() + "光栅亮");
                            }
                            if (bol)
                            {
                                IOMsg.Instance.AllBol = false;
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_start);
                                Console.WriteLine("yes3");
                                Thread.Sleep(200);
                                IOMsg.Instance.AllBol = true;
                                Thread.Sleep(200);
                            }
                        }
                        Thread.Sleep(10);
                    }
                }
                else if (ccInit == 2)
                {
                    while (true)
                    {
                        Console.WriteLine("yes4");
                        if (!WuLiaoCoffeeSel.Instance.BANNER2_Sel_Bol)
                        {
                            IOMsg.Instance.AllBol = true;
                            if (WuLiaoCoffeeSel.Instance.PushRodUP2_Sel_Bol)
                            {
                                Console.WriteLine("yes7");
                                IOMsg.Instance.AllBol = false;
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                                Thread.Sleep(200);
                                IOMsg.Instance.AllBol = true;
                                bol = false;
                                break;
                            }
                            Thread.Sleep(200);
                        }
                        else
                        {
                            Console.WriteLine(DateTime.Now.ToString());
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                            while (true)
                            {
                                if (WuLiaoCoffeeSel.Instance.PushRodUP2_Sel_Bol)
                                {
                                    Console.WriteLine("yes9");
                                    IOMsg.Instance.AllBol = false;
                                    Thread.Sleep(200);
                                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                                    Thread.Sleep(200);
                                    IOMsg.Instance.AllBol = true;
                                    bol = false;
                                    break;
                                }
                                if (!WuLiaoCoffeeSel.Instance.BANNER2_Sel_Bol)
                                {
                                    bol = true;
                                    break;
                                }
                                Thread.Sleep(200);
                                Console.WriteLine(DateTime.Now.ToString() + "光栅亮");
                            }
                            if (bol)
                            {
                                IOMsg.Instance.AllBol = false;
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                                Thread.Sleep(200);
                                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_start);
                                Console.WriteLine("yes3");
                                Thread.Sleep(200);
                                IOMsg.Instance.AllBol = true;
                                Thread.Sleep(200);
                            }
                        }
                        Thread.Sleep(10);
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("yesno");
                return;
            }
        }
        /// <summary>
        /// 出餐流程
        /// </summary>
        /// <param name="id">ordernum</param>
        /// <param name="ccInit">出餐几号</param>
        public void MakeMealMsg(string id, int ccInit, int ordergoodsid, int orderid)
        {
            try
            {
                while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                IOMsg.Instance.CFBol = false;
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_start);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_start);
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_start);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_start);
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                while (true)
                {
                    if (ccInit == 1)
                    {
                        if (WuLiaoCoffeeSel.Instance.PushRodDown1_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    else if (ccInit == 2)
                    {
                        if (WuLiaoCoffeeSel.Instance.PushRodDown2_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    Thread.Sleep(10);
                }
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);

                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                IOMsg.Instance.CFBol = true;
                ClientList clientList = new ClientList();
                clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList.code = 10;
                clientList.IsMake = true;
                SocketClients.Instance.client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                Thread.Sleep(200);
                int callidex = 0;
                string ids = "";
                //if (id.Length > 6)
                //    id = id.Substring(id.Length - 6, 6);
                //if (id.Length == 6)
                //{
                //    string read = id.Substring(0, 1) + " " + id.Substring(1, 1) + " " + id.Substring(2, 1) + " " + id.Substring(3, 1) + " " + id.Substring(4, 1) + " " + id.Substring(5, 1) + " ";
                //    string read1 = EnglishRead(id.Substring(0, 1)) + " " + EnglishRead(id.Substring(1, 1)) + " " + EnglishRead(id.Substring(2, 1)) + " " + EnglishRead(id.Substring(3, 1)) + " " + EnglishRead(id.Substring(4, 1)) + " " + EnglishRead(id.Substring(5, 1)) + " ";
                //    id = read;
                //    ids = read1;
                //}
                int year = 0;
                int month = 0;
                int day = 0;
                int hour = 0;
                int minute = 0;
                bool fqBol = false;
                try
                {
                    var coffee = instance.coffeeMakes.FirstOrDefault(a => a.OrderGoodsId == ordergoodsid && a.OrderId == orderid);
                    if (coffee != null)
                    {
                        if (coffee.QBDatetime.ToString().Length >= 12)
                        {
                            year = int.TryParse(coffee.QBDatetime.ToString().Substring(0, 4), out int years) ? years : 0;
                            month = int.TryParse(coffee.QBDatetime.ToString().Substring(4, 2), out int months) ? months : 0;
                            day = int.TryParse(coffee.QBDatetime.ToString().Substring(6, 2), out int days) ? days : 0;
                            hour = int.TryParse(coffee.QBDatetime.ToString().Substring(8, 2), out int hours) ? hours : 0;
                            minute = int.TryParse(coffee.QBDatetime.ToString().Substring(10, 2), out int minutes) ? minutes : 0;
                        }
                    }
                }
                catch (Exception)
                {
                }
                //try
                //{
                //    RecycleTimeSel timeSel = new RecycleTimeSel();
                //    timeSel.orderGoodsId = ordergoodsid;
                //    timeSel.orderId = orderid;
                //    string lists1 = JsonConvert.SerializeObject(timeSel);
                //    var ddd2 = HttpMsg.Instance.editDeviceOrderStatusMsg(lists1);
                //    if (ddd2 != null)
                //    {
                //        var list10 = JsonConvert.DeserializeObject<ListTimeMsg>(ddd2);
                //        if (list10 != null)
                //        {
                //            if (list10.code == "0" || list10.code == "1")
                //            {
                //                if (list10.msg.ToString().Length == 12)
                //                {
                //                    year = int.TryParse(list10.ToString().Substring(0, 4), out int years) ? years : 0;
                //                    month = int.TryParse(list10.ToString().Substring(0, 4), out int months) ? months : 0;
                //                    day = int.TryParse(list10.ToString().Substring(0, 4), out int days) ? days : 0;
                //                    hour = int.TryParse(list10.ToString().Substring(0, 4), out int hours) ? hours : 0;
                //                    minute = int.TryParse(list10.ToString().Substring(0, 4), out int minutes) ? minutes : 0;
                //                }
                //            }
                //        }
                //    }
                //}
                //catch (Exception)
                //{
                //}
                while (true)
                {
                    if (ccInit == 1)
                    {
                        if (!WuLiaoCoffeeSel.Instance.OutMealCup1_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {

                            if (callidex % 100 == 0)
                            {
                                //SpeechVoice.Instance.VoicePlayback(" NO." + ids + ",please pick up your coffee ");
                                DateTime date = DateTime.Now;
                                if (date.Year == year && date.Month == month && date.Day == day && date.Hour == hour && date.Minute == minute)
                                {
                                    if (MainWindow.isMake)
                                    {
                                        fqBol = true;
                                        MainWindow.isMake = false;
                                        break;
                                    }

                                }
                            }
                            Thread.Sleep(100);
                            callidex++;
                        }
                    }
                    else
                    {
                        if (!WuLiaoCoffeeSel.Instance.OutMealCup2_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {

                            if (callidex % 100 == 0)
                            {
                                DateTime date = DateTime.Now;
                                if (date.Year == year && date.Month == month && date.Day == day && date.Hour == hour && date.Minute == minute)
                                {
                                    if (MainWindow.isMake)
                                    {
                                        fqBol = true;
                                        MainWindow.isMake = false;
                                        break;
                                    }

                                }
                            }
                            Thread.Sleep(100);
                            callidex++;
                        }
                    }

                    Thread.Sleep(100);
                }

                Thread.Sleep(1000);
                //SpeechVoice.Instance.VoicePlayback("The door is closing，please watch your hands");
                //Thread.Sleep(5000);
                while (true)
                {
                    if (ccInit == 1)
                    {
                        if (!WuLiaoCoffeeSel.Instance.BANNER1_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    else if (ccInit == 2)
                    {
                        if (!WuLiaoCoffeeSel.Instance.BANNER2_Sel_Bol)
                        {
                            break;
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    Thread.Sleep(10);
                }
                Console.WriteLine("yes1");
                OutMealClose(ccInit);
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                if (ccInit == 1)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_end);
                else if (ccInit == 2)
                    IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_end);
                Thread.Sleep(200);
                Console.WriteLine("yes11");
                IOMsg.Instance.AllBol = true;
                IOMsg.Instance.CFBol = true;
                if (fqBol)
                {
                    QBMsg(orderid, ordergoodsid, ccInit == 1 ? 10 : 11);
                    MainWindow.isMake = true;
                }
                while (true)
                {
                    EditDeviceOrderStatus status = new EditDeviceOrderStatus();
                    status.orderGoodsId = ordergoodsid;
                    status.orderId = orderid;
                    status.status = 5;
                    string lists = JsonConvert.SerializeObject(status);
                    var ddd1 = HttpMsg.Instance.editDeviceOrderStatusMsg(lists);
                    if (ddd1 != null)
                    {
                        if (ddd1 != "")
                        {
                            var list10 = JsonConvert.DeserializeObject<ListMsg>(ddd1);
                            if (list10 != null)
                            {
                                if (list10.code == "0" || list10.code == "1")
                                {
                                    Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                    break;
                                }
                            }
                            Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                        }

                    }
                    Thread.Sleep(100);
                }
                //MainWindow.isYC = true;
                instance.coffeeMaking.Remove(coffeeMaking.FirstOrDefault(a => a.OrderId == orderid && a.OrderGoodsId == ordergoodsid && a.OrderNum == id));
                instance.coffeeMakes.Remove(coffeeMakes.FirstOrDefault(a => a.OrderId == orderid && a.OrderGoodsId == ordergoodsid && a.OrderNum == id));

            }
            catch (Exception)
            {
                return;
            }
        }

        public string EnglishRead(string id)
        {
            try
            {
                string name = "";
                switch (id)
                {
                    case "0":
                        name = "Zero";
                        break;
                    case "1":
                        name = "One";
                        break;
                    case "2":
                        name = "Two";
                        break;
                    case "3":
                        name = "Three";
                        break;
                    case "4":
                        name = "Four";
                        break;
                    case "5":
                        name = "Five";
                        break;
                    case "6":
                        name = "Six";
                        break;
                    case "7":
                        name = "Seven";
                        break;
                    case "8":
                        name = "Eight";
                        break;
                    case "9":
                        name = "Nine";
                        break;
                }
                return name;
            }
            catch (Exception)
            {
                return "";
            }
        }
        /// <summary>
        /// 存单
        /// </summary>
        public void CDMsg(DeviceOrderQueue orderQueue, string orderNum)
        {
            try
            {
                Thread.Sleep(200);
                int ycwz = !WuLiaoCoffeeSel.Instance.PrestoredPosition1_Sel_Bol ? 1 : !WuLiaoCoffeeSel.Instance.PrestoredPosition2_Sel_Bol ? 2 : !WuLiaoCoffeeSel.Instance.PrestoredPosition3_Sel_Bol ? 3 : !WuLiaoCoffeeSel.Instance.PrestoredPosition4_Sel_Bol ? 4 : !WuLiaoCoffeeSel.Instance.PrestoredPosition5_Sel_Bol ? 5 : !WuLiaoCoffeeSel.Instance.PrestoredPosition6_Sel_Bol ? 6 : !WuLiaoCoffeeSel.Instance.PrestoredPosition7_Sel_Bol ? 7 : !WuLiaoCoffeeSel.Instance.PrestoredPosition8_Sel_Bol ? 8 : 9;
                var ycMsg = !WuLiaoCoffeeSel.Instance.PrestoredPosition1_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD1_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition2_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD2_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition3_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD3_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition4_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD4_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition5_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD5_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition6_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD6_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition7_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD7_UP : !WuLiaoCoffeeSel.Instance.PrestoredPosition8_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD8_UP : RobotIOModel.Instance.LRobot_QCD9_UP;
                var ycMsgEnd = !WuLiaoCoffeeSel.Instance.PrestoredPosition1_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD1_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition2_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD2_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition3_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD3_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition4_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD4_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition5_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD5_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition6_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD6_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition7_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD7_Down : !WuLiaoCoffeeSel.Instance.PrestoredPosition8_Sel_Bol ? RobotIOModel.Instance.LRobot_QCD8_Down : RobotIOModel.Instance.LRobot_QCD9_Down;
                IOSerialPortRobot.Instance.SerialSend(ycMsg);
                Thread.Sleep(200);
                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCD_UP);
                Thread.Sleep(200);
                IOMsgRobot.Instance.RobotBol = false;
                Thread.Sleep(200);
                while (true)
                {
                    Thread.Sleep(200);
                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_CDWC);
                    Thread.Sleep(200);
                    if (IOMsgRobot.Instance.RobotBol)
                    {
                        Thread.Sleep(200);
                        IOSerialPortRobot.Instance.SerialSend(ycMsgEnd);
                        Thread.Sleep(200);
                        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCD_Down);
                        break;
                    }
                }
                if (coffeeMakes.Any(a => a.OrderNum == orderNum && a.OrderId == orderQueue.orderId && a.OrderGoodsId == orderQueue.id))
                {
                    var coffee = coffeeMakes.FirstOrDefault(a => a.OrderGoodsId == orderQueue.id && a.OrderId == orderQueue.orderId && a.OrderNum == orderNum);
                    coffee.PrestoredPosition = ycwz;
                }
                else
                {
                    CoffeeMakeModel makeModel = new CoffeeMakeModel();
                    makeModel.OrderGoodsId = orderQueue.id;
                    makeModel.OrderId = orderQueue.orderId;
                    makeModel.PrestoredPosition = ycwz;
                    makeModel.OrderNum = orderNum;
                    coffeeMakes.Add(makeModel);
                }
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// 取单
        /// </summary>
        public void QDMsg()
        {
            try
            {
                if (coffeeMakes.Any(a => a.Type == 1 && a.PrestoredPosition != 0))
                {
                    if (MainWindow.isMake)
                    {
                        if (WuLiaoCoffeeSel.Instance.PushRodUP1_Sel_Bol || WuLiaoCoffeeSel.Instance.PushRodUP2_Sel_Bol)
                        {
                            MainWindow.isMake = false;
                            var dd = coffeeMakes.FirstOrDefault(a => a.Type == 1 && a.PrestoredPosition != 0);
                            var ycMsg = dd.PrestoredPosition == 1 ? RobotIOModel.Instance.LRobot_QQD1_UP : dd.PrestoredPosition == 2 ? RobotIOModel.Instance.LRobot_QQD2_UP : dd.PrestoredPosition == 3 ? RobotIOModel.Instance.LRobot_QQD3_UP : dd.PrestoredPosition == 4 ? RobotIOModel.Instance.LRobot_QQD4_UP : dd.PrestoredPosition == 5 ? RobotIOModel.Instance.LRobot_QQD5_UP : dd.PrestoredPosition == 6 ? RobotIOModel.Instance.LRobot_QQD6_UP : dd.PrestoredPosition == 7 ? RobotIOModel.Instance.LRobot_QQD7_UP : dd.PrestoredPosition == 8 ? RobotIOModel.Instance.LRobot_QQD8_UP : RobotIOModel.Instance.LRobot_QQD9_UP;
                            var ycMsgEnd = dd.PrestoredPosition == 1 ? RobotIOModel.Instance.LRobot_QQD1_Down : dd.PrestoredPosition == 2 ? RobotIOModel.Instance.LRobot_QQD2_Down : dd.PrestoredPosition == 3 ? RobotIOModel.Instance.LRobot_QQD3_Down : dd.PrestoredPosition == 4 ? RobotIOModel.Instance.LRobot_QQD4_Down : dd.PrestoredPosition == 5 ? RobotIOModel.Instance.LRobot_QQD5_Down : dd.PrestoredPosition == 6 ? RobotIOModel.Instance.LRobot_QQD6_Down : dd.PrestoredPosition == 7 ? RobotIOModel.Instance.LRobot_QQD7_Down : dd.PrestoredPosition == 8 ? RobotIOModel.Instance.LRobot_QQD8_Down : RobotIOModel.Instance.LRobot_QQD9_Down;
                            Thread.Sleep(200);
                            IOSerialPortRobot.Instance.SerialSend(ycMsg);
                            Thread.Sleep(200);
                            IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QQD_UP);
                            Thread.Sleep(200);
                            IOMsgRobot.Instance.RobotBol = false;
                            Thread.Sleep(200);
                            while (true)
                            {
                                Thread.Sleep(200);
                                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QDWC);
                                Thread.Sleep(200);
                                if (IOMsgRobot.Instance.RobotBol)
                                {
                                    Thread.Sleep(200);
                                    IOSerialPortRobot.Instance.SerialSend(ycMsgEnd);
                                    Thread.Sleep(200);
                                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QQD_Down);
                                    break;
                                }
                            }
                            int CCInit = 0;
                            Thread.Sleep(200);
                            if (WuLiaoCoffeeSel.Instance.PushRodUP1_Sel_Bol)
                            {
                                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCC1_UP);
                                CCInit = 1;
                            }
                            else if (WuLiaoCoffeeSel.Instance.PushRodUP2_Sel_Bol)
                            {
                                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCC2_UP);
                                CCInit = 2;
                            }
                            IOMsgRobot.Instance.RobotBol = false;
                            while (true)
                            {
                                Thread.Sleep(200);
                                if (CCInit == 1)
                                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_DDCCK1);
                                else if (CCInit == 2)
                                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_DDCCK2);
                                Thread.Sleep(200);
                                if (IOMsgRobot.Instance.RobotBol)
                                {
                                    if (CCInit == 1)
                                    {
                                        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCC1_Down);
                                    }
                                    else if (CCInit == 2)
                                    {
                                        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QCC2_Down);
                                    }
                                    Thread.Sleep(200);
                                    break;
                                }
                            }
                            //var dd = coffeeMakes.FirstOrDefault(a => a.Type == 1 && a.PrestoredPosition != 0);
                            dd.Type = 2;
                            MainWindow.isMake = true;
                            TestDelegateInvoke testDelegate = new TestDelegateInvoke(Instance.MakeMealMsg);
                            testDelegate.BeginInvoke(dd.OrderNum, CCInit, dd.OrderGoodsId, dd.OrderId, null, null);
                        }
                    }
                }
                Thread.Sleep(1000);
            }
            catch (Exception)
            {
                Thread.Sleep(1000);
            }
        }
        public delegate void TestDelegateInvoke(string orderNum, int ccInit, int ordergoodsid, int orderid);

        /// <summary>
        /// 弃杯流程
        /// </summary>
        /// <param name="orderid"></param>
        /// <param name="ordergoodsid"></param>
        ///  <param name="qbInit">弃杯第几个口 1-9存单口 10 出餐口A  11 出餐口B</param>
        public void QBMsg(int orderid, int ordergoodsid, int qbInit)
        {
            try
            {
                Thread.Sleep(200);
                string qb = qbInit == 1 ? RobotIOModel.Instance.LRobot_QQD1_UP : qbInit == 2 ? RobotIOModel.Instance.LRobot_QQD2_UP : qbInit == 3 ? RobotIOModel.Instance.LRobot_QQD3_UP : qbInit == 4 ? RobotIOModel.Instance.LRobot_QQD4_UP : qbInit == 5 ? RobotIOModel.Instance.LRobot_QQD5_UP : qbInit == 6 ? RobotIOModel.Instance.LRobot_QQD6_UP : qbInit == 7 ? RobotIOModel.Instance.LRobot_QQD7_UP : qbInit == 8 ? RobotIOModel.Instance.LRobot_QQD8_UP : qbInit == 9 ? RobotIOModel.Instance.LRobot_QQD9_UP : qbInit == 10 ? RobotIOModel.Instance.LRobot_QCC1_UP : RobotIOModel.Instance.LRobot_QCC2_UP;
                string qbend = qbInit == 1 ? RobotIOModel.Instance.LRobot_QQD1_Down : qbInit == 2 ? RobotIOModel.Instance.LRobot_QQD2_Down : qbInit == 3 ? RobotIOModel.Instance.LRobot_QQD3_Down : qbInit == 4 ? RobotIOModel.Instance.LRobot_QQD4_Down : qbInit == 5 ? RobotIOModel.Instance.LRobot_QQD5_Down : qbInit == 6 ? RobotIOModel.Instance.LRobot_QQD6_Down : qbInit == 7 ? RobotIOModel.Instance.LRobot_QQD7_Down : qbInit == 8 ? RobotIOModel.Instance.LRobot_QQD8_Down : qbInit == 9 ? RobotIOModel.Instance.LRobot_QQD9_Down : qbInit == 10 ? RobotIOModel.Instance.LRobot_QCC1_Down : RobotIOModel.Instance.LRobot_QCC2_Down;
                IOSerialPortRobot.Instance.SerialSend(qb);
                Thread.Sleep(200);
                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QFQ_UP);
                //IOMsgRobot.Instance.RobotBol = false;
                Thread.Sleep(200);
                //while (true)
                //{
                //    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QBWC);
                //    Thread.Sleep(200);
                //    if (IOMsgRobot.Instance.RobotBol)
                //    {
                //        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QFQ_Down);
                //        break;
                //    }
                //}
                while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                IOMsg.Instance.CFBol = false;
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBHT_start);
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                while (!WuLiaoCoffeeSel.Instance.GiveUPAfter) { Thread.Sleep(10); }
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBHT_end);
                Thread.Sleep(200);
                IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QBWC_UP);
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                IOMsgRobot.Instance.RobotBol = false;
                Thread.Sleep(200);
                while (true)
                {
                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_JQRQBWC);
                    Thread.Sleep(200);
                    if (IOMsgRobot.Instance.RobotBol)
                    {
                        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QFQ_Down);
                        Thread.Sleep(200);
                        IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QBWC_Down);
                        Thread.Sleep(200);
                        break;
                    }
                }
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBQJ_start);
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                while (!WuLiaoCoffeeSel.Instance.GiveUPBefor) { Thread.Sleep(10); }
                IOMsg.Instance.AllBol = false;
                Thread.Sleep(200);
                IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBQJ_end);
                Thread.Sleep(200);
                IOMsg.Instance.AllBol = true;
                IOMsg.Instance.CFBol = true;
                //Thread.Sleep(200);
                //IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QBWC_UP);
                IOMsgRobot.Instance.RobotBol = false;
                Thread.Sleep(200);
                while (true)
                {
                    IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_DYD);
                    Thread.Sleep(200);
                    if (IOMsgRobot.Instance.RobotBol)
                    {
                        // IOSerialPortRobot.Instance.SerialSend(RobotIOModel.Instance.LRobot_QBWC_Down);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Thread.Sleep(1000);
            }
        }
        public void QBTimeMsg()
        {
            while (true)
            {
                try
                {
                    if (coffeeMakes.Count > 0)
                    {
                        foreach (var item in coffeeMakes)
                        {
                            if (item.PrestoredPosition != 0 && item.Type == 0)
                            {
                                int year = 0;
                                int month = 0;
                                int day = 0;
                                int hour = 0;
                                int minute = 0;
                                try
                                {
                                    RecycleTimeSel timeSel = new RecycleTimeSel();
                                    timeSel.orderGoodsId = item.OrderGoodsId;
                                    timeSel.orderId = item.OrderId;
                                    string lists1 = JsonConvert.SerializeObject(timeSel);
                                    var ddd2 = HttpMsg.Instance.editDeviceOrderStatusMsg(lists1);
                                    if (ddd2 != null)
                                    {
                                        var list10 = JsonConvert.DeserializeObject<ListTimeMsg>(ddd2);
                                        if (list10 != null)
                                        {
                                            if (list10.code == "0" || list10.code == "1")
                                            {
                                                if (list10.msg.ToString().Length == 12)
                                                {
                                                    year = int.TryParse(list10.ToString().Substring(0, 4), out int years) ? years : 0;
                                                    month = int.TryParse(list10.ToString().Substring(0, 4), out int months) ? months : 0;
                                                    day = int.TryParse(list10.ToString().Substring(0, 4), out int days) ? days : 0;
                                                    hour = int.TryParse(list10.ToString().Substring(0, 4), out int hours) ? hours : 0;
                                                    minute = int.TryParse(list10.ToString().Substring(0, 4), out int minutes) ? minutes : 0;
                                                }
                                            }
                                        }
                                    }
                                }
                                catch { }
                                DateTime date = DateTime.Now;
                                if (date.Year == year && date.Month == month && date.Day == day && date.Hour == hour && date.Minute == minute)
                                {
                                    if (MainWindow.isMake)
                                    {
                                        MainWindow.isMake = false;
                                        QBMsg(item.OrderId, item.OrderGoodsId, item.PrestoredPosition);
                                        while (true)
                                        {
                                            EditDeviceOrderStatus status = new EditDeviceOrderStatus();
                                            status.orderGoodsId = item.OrderGoodsId;
                                            status.orderId = item.OrderId;
                                            status.status = 5;
                                            string lists = JsonConvert.SerializeObject(status);
                                            var ddd1 = HttpMsg.Instance.editDeviceOrderStatusMsg(lists);
                                            if (ddd1 != null)
                                            {
                                                if (ddd1 != "")
                                                {
                                                    var list10 = JsonConvert.DeserializeObject<ListMsg>(ddd1);
                                                    if (list10 != null)
                                                    {
                                                        if (list10.code == "0" || list10.code == "1")
                                                        {
                                                            Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                                            break;
                                                        }
                                                    }
                                                    Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                                }

                                            }
                                            Thread.Sleep(100);
                                        }
                                        // MainWindow.isYC = true;
                                        instance.coffeeMaking.Remove(coffeeMaking.FirstOrDefault(a => a.OrderId == item.OrderId && a.OrderGoodsId == item.OrderGoodsId && a.OrderNum == item.OrderNum));
                                        instance.coffeeMakes.Remove(coffeeMakes.FirstOrDefault(a => a.OrderId == item.OrderId && a.OrderGoodsId == item.OrderGoodsId && a.OrderNum == item.OrderNum));

                                        MainWindow.isMake = true;
                                    }

                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {

                }
                Thread.Sleep(1000);
            }

        }
        public void SpeakShow()
        {
            try
            {
                using (HttpListener listener = new HttpListener())
                {
                    listener.Prefixes.Add("http://localhost:8080/");
                    listener.Start();
                    Console.WriteLine("服务器启动，正在监听请求...");

                    while (true)
                    {
                        HttpListenerContext context = listener.GetContext();
                        HttpListenerResponse response = context.Response;

                        string responseString = "Hello, World!";
                        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                        response.ContentLength64 = buffer.Length;
                        System.IO.Stream output = response.OutputStream;
                        output.Write(buffer, 0, buffer.Length);
                        output.Close();
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
    }
}
